/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/serializer/NumberFieldSerializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: NumberFieldSerializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.serializer;

import com.elancom.framework.commons.json.util.FieldInfo;

/**
 * @author elancom
 */
class NumberFieldSerializer extends FieldSerializer {

	public NumberFieldSerializer(FieldInfo fieldInfo) {
		super(fieldInfo);
	}

	@Override
	public void writeProperty(JSONSerializer serializer, Object propertyValue) throws Exception {
		final SerializeWriter out = serializer.getWriter();

		writePrefix(serializer);

		final Object value = propertyValue;

		if (value == null) {
			if (out.isEnabled(SerializerFeature.WriteNullNumberAsZero)) {
				out.write('0');
			} else {
				out.writeNull();
			}
			return;
		}

		out.append(value.toString());
	}
}
